﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TLECDataLayer;

namespace CreateReservations
{
    public partial class PurchaseTickets : System.Web.UI.Page
    {
        private TLECDataLayer.Event selectedEve;

        protected void Page_Load(object sender, EventArgs e)
        {
            int tmp;
            if (Request.Params["eveId"] != null && int.TryParse(Request.Params["eveId"], out tmp))
            {
                selectedEve = TLECDataLayer.Events.GetEventById(Convert.ToInt32(Request.Params["eveId"]));
            }
            else
            {
                selectedEve = null;
            }
        }

        protected void createLB_Click(object sender, EventArgs e)
        {
            Page.Validate("myGroup");

            if (Page.IsValid && selectedEve != null)
            {
                int id = Reservations.CreateReservation(this.nameTxt.Text, Convert.ToInt32(this.numTxt.Text), 
                    selectedEve.EventId, DateTime.Now, this.addTxt.Text);

                Response.Redirect("~/PurchaseCreated.aspx?resId=" + id);
            }
            else if (selectedEve == null)
            {
                this.errLbl.Text = "You should select event first!";
            }
        }
    }
}